package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.db.User;
import com.tanhua.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;


    @Override
    public Long saveUser(User user) {
        user.setCreated(new Date());
        user.setUpdated(new Date());
        userMapper.insert(user);
        return user.getId(); //主键返回策略  mybatisplus自动开启了主键返回
    }

    @Override
    public User findByPhone(String phone) {
        QueryWrapper<User> qw = new QueryWrapper<>(); //条件
        qw.eq("phone",phone);
        User user = userMapper.selectOne(qw);
        return user;
    }
}
